<script type="text/javascript">
    function addChecked(sNode) {
        var index = sNode.selectedIndex;
        var option = sNode.options[index];
        option.selected = false;
        document.getElementById("checkedGroup").add(option);
        setGroup()
    }

    function delChecked(sNode) {
        var index = sNode.selectedIndex;
        var option = sNode.options[index];
        option.selected = false;
        document.getElementById("allGroup").add(option);
        setGroup()
    }

    function setGroup() {
        var adminId = "${adminId!}";
        var groupIds = "";
        var checkedGroup = document.getElementById("checkedGroup");
        var length = checkedGroup.length;
        for (var i = 0; i < length; i++) {
            groupIds += checkedGroup.options[i].value + ",";
        }
        post("/b/admin/setGroup", {"id": adminId, "groupIds": groupIds}, function (res) {
            if (!res.success) {
                msg("操作失败")
                return
            }
            msg("设置成功")
        }, function () {
            systemErr();
        })
    }
</script>
<div class="modal-body">
    <div class="row">
        <div class="col-md-6">
            <div class="panel-heading">
                <h4 class="panel-title">
                    未选分组
                </h4>
            </div>
            <div class="panel-body">
                <select id="allGroup" ondblclick="addChecked(this);" multiple="multiple" size="5" class="form-control">
                    <% for(group in noCheckedList){ %>
                    <option value='${group.id!}'>${group.name!}</option>
                    <% } %>
                </select>
            </div>
        </div>
        <div class="col-md-6">
            <div class="panel-heading">
                <h4 class="panel-title">
                    已选分组
                </h4>
            </div>
            <div class="panel-body">
                <select id="checkedGroup" ondblclick="delChecked(this);" multiple="multiple" size="5"
                        class="form-control">
                    <% for(group in checkedList){ %>
                    <option value='${group.id!}'>${group.name!}</option>
                    <% } %>
                </select>
            </div>
        </div>
    </div>
</div>